﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;

/// <summary>
/// WebRequestApi의 요약 설명입니다.
/// </summary>
public class WebRequestApi
{
    private string url = string.Empty;

	private WebRequestApi()
	{
	}

    /// <summary>
    /// 주어진 url로 HttpWebRequest url을 초기화하는 생성자
    /// </summary>
    /// <param name="_url"></param>
    public WebRequestApi(string _url)
    {
        url = _url;
    }

    /// <summary>
    /// 주어진 url을 호출하여 실행 결과를 문자열로 반환
    /// </summary>
    /// <returns></returns>
    public string GetWebResponse()
    {
        HttpWebRequest hw = null;
        HttpWebResponse hwr = null;
        StreamReader sr = null;
        string source = "";

        hw = (HttpWebRequest)WebRequest.Create(url);
        hwr = (HttpWebResponse)hw.GetResponse();

        sr = new StreamReader(hwr.GetResponseStream(), Encoding.Default);
        source = sr.ReadToEnd();


        sr.Close();
        hwr.Close();
        hw.Abort();

        return source;
    }
}
